import 'dart:convert';
import 'package:flutter_logger_server/utils/log_utils.dart';
import 'package:flutter_logger_server/flutter_logger_server.dart';

class MessageLoggerPlugin {
  void sendMessageLog({
    String? id,
    DateTime? createTime,
    String? message,
  }) {
    if (!FlutterLoggerServer.instance.isStarted) {
      LogUtils.log("没有初始化，无法发送消息");
      return;
    }
    if (message == null) {
      return;
    }
    FlutterLoggerServer.instance.webSocketUtils.postMessage("message_log", jsonEncode({
      "id": id,
      "createTime": createTime?.millisecondsSinceEpoch,
      "message": message,
    }));
  }
}
